package org.jeecg.modules.bpm.activiti.rest.editor.main;

import org.activiti.engine.ActivitiException;
import org.apache.commons.io.IOUtils;
import org.jeecg.modules.extbpm.util.CommonRandomUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;

/**
 * Model Editor
 * @author scott
 */
@RestController("stencilsetRestResource")
@RequestMapping("service")
public class StencilsetRestResource {
  private final String STENCILSET_JSON = CommonRandomUtil.trim("stencilset.json");
  
  @RequestMapping(value="/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
  public @ResponseBody String getStencilset() {
    InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream(STENCILSET_JSON);
    try {
      return IOUtils.toString(stencilsetStream, "utf-8");
    } catch (Exception e) {
      throw new ActivitiException("Error while loading stencil set", e);
    }
  }
}
